<template>
  <view class="work-page">
    <view class="temperature">
      <view class="text"> 当前温度°C </view>
      <view class="input">
        <input
          inputmode="decimal"
          @focus="currentFocus = -1"
          :selection-start="0"
          :selection-end="10000"
          v-model="workMainData.real_temperature"
          placeholder="请输入当前温度"
        />
      </view>
      <view class="text"> 当前湿度% </view>
      <view class="input">
        <input
          inputmode="decimal"
          @focus="currentFocus = -1"
          :selection-start="0"
          :selection-end="10000"
          v-model="workMainData.real_humidity"
          placeholder="请输入当前湿度"
        />
      </view>
    </view>
    <template v-for="(grp, index) in groupWorksubData" :key="index">
      <view class="table">
        <view :class="{ grp: workMainData.key, nkey: !workMainData.key }" @click="onCheck(index)">
          <view class="container">
            <span>
              #{{ index + 1 }}(dv= {{ initFlag[index] ? '' : grp[0].dv }},dh={{
                initFlag[index] ? '' : grp[0].dh
              }},
            </span>
            <span
              >甩挡差之差: <checkbox :checked="workMainData.pass_flag" :disabled="true" />)
            </span>
          </view>
        </view>
        <view class="row1 flex-center-between">
          <view class="left-content" :class="{ active: grp[p[0]].no_pass }">
            <!-- {{ p[0] }}-{{ grp[p[0]].id }}-0 -->
            <input
              :inputmode="currInputMode"
              placeholder="请输入"
              class="input"
              :disabled="!worktoolStore.deviceId.currDeviceId || users.includes(currentUser[0])"
              :value="grp[p[0]].decimal ? grp[p[0]].real_value : grp[p[0]].real_value2"
              :selection-start="0"
              :selection-end="10000"
              :focus="currentIndex == grp[p[0]].id"
              @focus="onFocus(p[0], grp)"
              @input="
                (e) => {
                  let eValue = Number(e.detail.value)
                  grp[p[0]].decimal
                    ? (grp[p[0]].real_value = eValue)
                    : (grp[p[0]].real_value2 = eValue)
                }
              "
              @blur="onBlur(grp[p[0]])"
              @confirm="onConfirm(p[0], grp)"
            />
            <view class="text">#{{ index + 1 }}-{{ grp[p[0]].position_id[1] }}</view>
          </view>
          <view v-if="checkFlag[index]">
            <input
              placeholder="请输入"
              inputmode="none"
              class="check"
              :disabled="!worktoolStore.deviceId.currDeviceId"
              :value="grp[p[0]].decimal ? grp[p[0]].check_value : grp[p[0]].check_value2"
              :selection-start="0"
              :selection-end="10000"
              :focus="currentCheckIndex == grp[p[0]].id"
              @focus="onCheckFocus(p[0], grp)"
              @input="
                (e) => {
                  let eValue = Number(e.detail.value)
                  grp[p[0]].decimal
                    ? (grp[p[0]].check_value = eValue)
                    : (grp[p[0]].check_value2 = eValue)
                }
              "
              @blur="onBlurCheck(grp[p[0]])"
              @confirm="onCheckConfirm(p[0], grp)"
            />
            <view class="text">复测#{{ index + 1 }}-{{ grp[p[0]].position_id[1] }}</view>
          </view>
          <!-- Number(grp[p[1] - 1].real_value) + Number(grp[p[1] - 1].real_value2) === 0.0 -->
          <view class="right-content" :class="{ active: grp[p[1]].no_pass }">
            <!-- {{ p[1] }}-{{ grp[p[1]].id }}-1 -->
            <input
              placeholder="请输入"
              :inputmode="currInputMode"
              class="input"
              :disabled="!worktoolStore.deviceId.currDeviceId || users.includes(currentUser[0])"
              :value="grp[p[1]].decimal ? grp[p[1]].real_value : grp[p[1]].real_value2"
              :selection-start="0"
              :selection-end="10000"
              :focus="currentIndex == grp[p[1]].id"
              @focus="onFocus(p[1], grp)"
              @input="
                (e) => {
                  let eValue = Number(e.detail.value)
                  grp[p[1]].decimal
                    ? (grp[p[1]].real_value = eValue)
                    : (grp[p[1]].real_value2 = eValue)
                }
              "
              @blur="onBlur(grp[p[1]])"
              @confirm="onConfirm(p[1], grp)"
            />
            <view class="text">#{{ index + 1 }}-{{ grp[p[1]].position_id[1] }}</view>
          </view>
          <view v-if="checkFlag[index]">
            <input
              placeholder="请输入"
              inputmode="none"
              class="check"
              :disabled="!worktoolStore.deviceId.currDeviceId"
              :value="grp[p[1]].decimal ? grp[p[1]].check_value : grp[p[1]].check_value2"
              :selection-start="0"
              :selection-end="10000"
              :focus="currentCheckIndex == grp[p[1]].id"
              @focus="onCheckFocus(p[1], grp)"
              @input="
                (e) => {
                  let eValue = Number(e.detail.value)
                  grp[p[1]].decimal
                    ? (grp[p[1]].check_value = eValue)
                    : (grp[p[1]].check_value2 = eValue)
                }
              "
              @blur="onBlurCheck(grp[p[1]])"
              @confirm="onCheckConfirm(p[1], grp)"
            />
            <view class="text">复测#{{ index + 1 }}-{{ grp[p[1]].position_id[1] }}</view>
          </view>
        </view>
        <view class="row2 flex-center-between">
          <!-- Number(grp[p[2] - 1].real_value) + Number(grp[p[2] - 1].real_value2) === 0.0 -->
          <view class="left-content" :class="{ active: grp[p[2]].no_pass }">
            <!-- {{ p[2] }}-{{ grp[p[2]].id }}-2 -->
            <input
              placeholder="请输入"
              :inputmode="currInputMode"
              class="input"
              :disabled="!worktoolStore.deviceId.currDeviceId || users.includes(currentUser[0])"
              :value="grp[p[2]].decimal ? grp[p[2]].real_value : grp[p[2]].real_value2"
              :selection-start="0"
              :selection-end="10000"
              :focus="currentIndex == grp[p[2]].id"
              @focus="onFocus(p[2], grp)"
              @input="
                (e) => {
                  let eValue = Number(e.detail.value)
                  grp[p[2]].decimal
                    ? (grp[p[2]].real_value = eValue)
                    : (grp[p[2]].real_value2 = eValue)
                }
              "
              @blur="onBlur(grp[p[2]])"
              @confirm="onConfirm(p[2], grp)"
            />
            <view class="text">#{{ index + 1 }}-{{ grp[p[2]].position_id[1] }}</view>
          </view>
          <view v-if="checkFlag[index]">
            <input
              placeholder="请输入"
              inputmode="none"
              class="check"
              :disabled="!worktoolStore.deviceId.currDeviceId"
              :value="grp[p[2]].decimal ? grp[p[2]].check_value : grp[p[2]].check_value2"
              :selection-start="0"
              :selection-end="10000"
              :focus="currentCheckIndex == grp[p[2]].id"
              @focus="onCheckFocus(p[2], grp)"
              @input="
                (e) => {
                  let eValue = Number(e.detail.value)
                  grp[p[2]].decimal
                    ? (grp[p[2]].check_value = eValue)
                    : (grp[p[2]].check_value2 = eValue)
                }
              "
              @blur="onBlurCheck(grp[p[2]])"
              @confirm="onCheckConfirm(p[2], grp)"
            />
            <view class="text">复测#{{ index + 1 }}-{{ grp[p[2]].position_id[1] }}</view>
          </view>
          <!-- Number(grp[p[3] - 1].real_value) + Number(grp[p[3] - 1].real_value2) === 0.0 -->
          <view class="right-content" :class="{ active: grp[p[3]].no_pass }">
            <!-- {{ p[3] }}-{{ grp[p[3]].id }}-3 -->
            <input
              placeholder="请输入"
              :inputmode="currInputMode"
              class="input"
              :disabled="!worktoolStore.deviceId.currDeviceId || users.includes(currentUser[0])"
              :value="grp[p[3]].decimal ? grp[p[3]].real_value : grp[p[3]].real_value2"
              :selection-start="0"
              :selection-end="10000"
              :focus="currentIndex == grp[p[3]].id"
              @focus="onFocus(p[3], grp)"
              @input="
                (e) => {
                  let eValue = Number(e.detail.value)
                  grp[p[3]].decimal
                    ? (grp[p[3]].real_value = eValue)
                    : (grp[p[3]].real_value2 = eValue)
                }
              "
              @blur="onBlur(grp[p[3]])"
              @confirm="onConfirm(p[3], grp)"
            />
            <view class="text">#{{ index + 1 }}-{{ grp[p[3]].position_id[1] }}</view>
          </view>
          <view v-if="checkFlag[index]">
            <input
              placeholder="请输入"
              inputmode="none"
              class="check"
              :disabled="!worktoolStore.deviceId.currDeviceId"
              :value="grp[p[3]].decimal ? grp[p[3]].check_value : grp[p[3]].check_value2"
              :selection-start="0"
              :selection-end="10000"
              :focus="currentCheckIndex == grp[p[3]].id"
              @focus="onCheckFocus(p[3], grp)"
              @input="
                (e) => {
                  let eValue = Number(e.detail.value)
                  grp[p[3]].decimal
                    ? (grp[p[3]].check_value = eValue)
                    : (grp[p[3]].check_value2 = eValue)
                }
              "
              @blur="onBlurCheck(grp[p[3]])"
              @confirm="onCheckConfirm(p[3], grp)"
            />
            <view class="text">复测#{{ index + 1 }}-{{ grp[p[3]].position_id[1] }}</view>
          </view>
        </view>
        <!-- Number(grp[p[4] - 1].real_value) + Number(grp[p[4] - 1].real_value2) === 0.0 -->
        <view class="row4 flex-center">
          <view class="content" :class="{ active: grp[p[4]].no_pass }">
            <!-- {{ p[4] }}-{{ grp[p[4]].id }}-4 -->
            <input
              placeholder="请输入"
              :inputmode="currInputMode"
              class="input"
              :disabled="!worktoolStore.deviceId.currDeviceId || users.includes(currentUser[0])"
              :value="grp[p[4]].decimal ? grp[p[4]].real_value : grp[p[4]].real_value2"
              :selection-start="0"
              :selection-end="10000"
              :focus="currentIndex == grp[p[4]].id"
              @focus="onFocus(p[4], grp)"
              @input="
                (e) => {
                  let eValue = Number(e.detail.value)
                  grp[p[4]].decimal
                    ? (grp[p[4]].real_value = eValue)
                    : (grp[p[4]].real_value2 = eValue)
                }
              "
              @blur="onBlur(grp[p[4]])"
              @confirm="onConfirm(p[4], grp)"
            />
            <view class="text">#{{ index + 1 }}-{{ grp[p[4]].position_id[1] }}</view>
          </view>
          <view v-if="checkFlag[index]">
            <input
              placeholder="请输入"
              inputmode="none"
              class="check"
              :disabled="!worktoolStore.deviceId.currDeviceId"
              :value="grp[p[4]].decimal ? grp[p[4]].check_value : grp[p[4]].check_value2"
              :selection-start="0"
              :selection-end="10000"
              :focus="currentCheckIndex == grp[p[4]].id"
              @focus="onCheckFocus(p[4], grp)"
              @input="
                (e) => {
                  let eValue = Number(e.detail.value)
                  grp[p[4]].decimal
                    ? (grp[p[4]].check_value = eValue)
                    : (grp[p[4]].check_value2 = eValue)
                }
              "
              @blur="onBlurCheck(grp[p[4]])"
              @confirm="onCheckConfirm(p[4], grp)"
            />
            <view class="text">复测#{{ index + 1 }}-{{ grp[p[4]].position_id[1] }}</view>
          </view>
        </view>
      </view>
    </template>
  </view>
</template>
<script setup>
import { onShow } from '@dcloudio/uni-app'
import { ref, onMounted, onUnmounted, computed } from 'vue'
import { useWorkmainStore, useWorksubStore, useWorktoolStore, useUserStore } from '@/stores'
import { dateShow } from '@/utils/utils.js'
import { emitter } from '@/EventBus'

const workMain = useWorkmainStore()
const worksubStore = useWorksubStore()
const userStore = useUserStore()
const worktoolStore = useWorktoolStore()

//顺时针input顺序(从上到下，从左到右的顺序)对应的数据
const pcw = ref([4, 0, 3, 1, 2])
//逆时针input顺序对应的数据
const pccw = ref([0, 4, 1, 3, 2])

//旋转方向时的索引
const currentIndex = ref(0)
//旋转方向时的复测的索引
const currentCheckIndex = ref(0)

//最终的旋转数组，在show中根据数据设定
const p = ref({})
function onConfirm(q, grp) {
  // setTimeout(() => {
  if (grp[q + 1] === undefined) {
    currentIndex.value = grp[0].id
  } else {
    currentIndex.value = grp[q + 1].id
  }
  // }, 0)
}
function onCheckConfirm(q, grp) {
  // setTimeout(() => {
  if (grp[q + 1] === undefined) {
    currentCheckIndex.value = grp[0].id
  } else {
    currentCheckIndex.value = grp[q + 1].id
  }
  // }, 250)
}

const workMainId = ref()
// 当前work-main数据
const workMainData = ref({})
// worksub数据
const worksubData = ref()
//当前使用的设备
// const deviceId = ref({})
// deviceId.value = worktoolStore.deviceId
//可放行的用户
const users = ref([])
//当前用户
const currentUser = ref([])
//聚焦在real_value
const focusItem = ref({})
//选中复测
const checkFlag = ref({})
//聚焦在check_value
const focusCheckItem = ref([])
//将worksub按6条记录分一组
const groupWorksubData = ref([])
//存放dvdh误差值
const grpForDvDh = ref([])
//初始状态的判断,index组数为数组下标，其值当real_value=0时为true否则为false
const initFlag = ref([])
//每条数据的字段是real_value还是real_value2
// let realValList = []
function onCheckFocus(q, grp) {
  //设置数组0：为点击的是复测框，1：为点击的item
  console.log('onCheckFocus')
  currentCheckIndex.value = grp[q].id
  focusCheckItem.value[0] = true
  focusCheckItem.value[1] = q
  focusCheckItem.value[2] = grp
}
function onCheck(index) {
  if (workMainData.value.key) {
    checkFlag.value[index] = !checkFlag.value[index]
    console.log(checkFlag.value)
  }
}
function onFocus(q, grp) {
  //如果点击的不是复测框，需要将focusCheckItem.value[0]设置为false
  console.log('onFocus')
  focusCheckItem.value[0] = false
  currentIndex.value = grp[q].id
  focusItem.value[0] = q
  focusItem.value[1] = grp
  // console.log(focusItem.value)

  // console.log(focusItem.value)
}
function onBlur(item) {
  let real_val = Number(item.real_value)
  let real_val2 = Number(item.real_value2)
  item.decimal ? (item.real_value = real_val.toFixed(3)) : (item.real_value2 = real_val2.toFixed(2))
  item.datetime_work = dateShow()[0]
  item.datetimeUTC = dateShow()[1]
  item.operator_id = currentUser.value[0]
  item.deviceId = worktoolStore.deviceId.currDeviceId
  // if (item.decimal) {
  //   if (item.real_value < item.min_value || item.real_value > item.max_value) {
  //     item.no_pass = true
  //   } else {
  //     item.no_pass = false
  //   }
  // } else {
  //   if (item.real_value2 < item.min_value2 || item.real_value2 > item.max_value2) {
  //     item.no_pass = true
  //   } else {
  //     item.no_pass = false
  //   }
  // }
  calcDvDh()
}
function onBlurCheck(item) {
  let check_val = Number(item.check_value)
  let check_val2 = Number(item.check_value2)
  item.decimal
    ? (item.check_value = check_val.toFixed(3))
    : (item.check_value2 = check_val2.toFixed(2))
  // item.datetime_work = dateShow()[0]
  // item.datetimeUTC = dateShow()[1]
  // item.operator_id = currentUser.value[0]
  item.deviceId = worktoolStore.deviceId.currDeviceId
  // if (item.decimal) {
  //   if (item.real_value < item.min_value || item.real_value > item.max_value) {
  //     item.no_pass = true
  //   } else {
  //     item.no_pass = false
  //   }
  // } else {
  //   if (item.real_value2 < item.min_value2 || item.real_value2 > item.max_value2) {
  //     item.no_pass = true
  //   } else {
  //     item.no_pass = false
  //   }
  // }
  calcDvDh()
}
//worksub.no_pass 更新workmain.no_pass,以便判断是否操作完，并且符合数据范围，可以上传,index为组数
// function updateMainNopass() {
//   calcDvDh()
//   // workMainData.value.no_pass = !worksubData.value.every((element) => {
//   //   return !element.no_pass
//   // })
// }
//计算是否real_value都为0 ，即初始状态。即获取initFlag[]
function calcInit() {
  //获取对应组数的所有real_value的值列表
  let initRealVal = []
  for (let index = 0; index < groupWorksubData.value.length; index++) {
    initRealVal[index] = groupWorksubData.value[index].map((item) => {
      let r = item.decimal ? 'real_value' : 'real_value2'
      // console.log(item[r])
      return item[r]
    })
  }
  console.log('realVal', initRealVal)
  for (let index = 0; index < groupWorksubData.value.length; index++) {
    initFlag.value[index] = initRealVal[index].every((item) => {
      return item === 0
    })
  }
  console.log(initFlag.value)
}
//计算误差dv,dh
function calcDvDh() {
  //计算dv,dh
  //根据decimal ,获取数据是real_value还是real_value2
  let pass_allow = parseFloat(workMainData.value.pass_allow)
  for (let index = 0; index < groupWorksubData.value.length; index++) {
    let realValList = groupWorksubData.value[index].map((item) => {
      return item.decimal ? 'real_value' : 'real_value2'
    })
    let dv
    let dh
    // dv=v3 -(v1+v5)/2,dh=v4-v2
    dv = Math.abs(
      (parseFloat(groupWorksubData.value[index][0][realValList[0]]) +
        parseFloat(groupWorksubData.value[index][4][realValList[4]])) /
        2 -
        parseFloat(groupWorksubData.value[index][2][realValList[2]]),
    ).toFixed(2)
    //dh=v4-v2
    dh = Math.abs(
      parseFloat(groupWorksubData.value[index][3][realValList[3]]) -
        parseFloat(groupWorksubData.value[index][1][realValList[1]]),
    ).toFixed(2)
    grpForDvDh.value[index] = {
      dv: parseFloat(dv),
      dh: parseFloat(dh),
    }
    // 按组设置每条sub数据的no_pass
    //-no _pass<=dv[i]<= pass_allow &&
    //-no _pass<=dh[i]<= pass_allow
    //保存数据
    for (let i = 0; i < groupWorksubData.value[index].length; i++) {
      if (dv <= pass_allow && dh <= pass_allow && !initFlag.value[index]) {
        groupWorksubData.value[index][i].no_pass = false
      } else {
        groupWorksubData.value[index][i].no_pass = true
      }
      groupWorksubData.value[index][i].dv = dv
      groupWorksubData.value[index][i].dh = dh
    }
  }
  // -pass_allow<=dv[i]-dv[i+1]<= pass_allow &&
  // -pass_allow<=dh[i]-dh[i+1]<= pass_allow
  console.log('grpForDvDh.value', grpForDvDh.value)
  //组数大于1并且所有组数都不是初始值(0)状态时，循环计算相邻误差
  if (grpForDvDh.value.length > 1 && initFlag.value.every((element) => element === false)) {
    console.log('initFlag.value', initFlag.value)
    for (let i = 0; i < grpForDvDh.value.length - 1; i++) {
      workMainData.value.pass_flag =
        Math.abs(grpForDvDh.value[i].dv - grpForDvDh.value[i + 1].dv) <= pass_allow &&
        Math.abs(grpForDvDh.value[i].dh - grpForDvDh.value[i + 1].dh) <= pass_allow
    }
    //只有一组并且都不是初始化状态时(0),设置pass_flag为true即只考虑dv,dh满足否
  } else if (initFlag.value.every((element) => element === false)) {
    workMainData.value.pass_flag = true
  }
  //notpass = 必须满足所有!sub.no_pass都通过，这时notpass 才为false
  let notpass = !worksubData.value.every((element) => {
    return !element.no_pass
  })
  workMainData.value.no_pass = notpass && !workMainData.value.pass_flag
}
// function handleDataRecieved(result) {
//   let gotValue = []
//   let readVal = ab2char(result.value)
//   let value = toValue(readVal).value
//   let unit = toValue(readVal).unit
//   gotValue[0] = value
//   gotValue[1] = unit
//   console.log(gotValue)
//   processBleData(gotValue[0])
// }
//input组件inputmode，判断是否跳出软键盘
const currInputMode = computed(() => {
  if (!worktoolStore.notBluedev) {
    console.log('none')
    return 'none'
  } else {
    console.log('decimal')
    return 'decimal'
  }
})
function onClickBlue(item) {
  clickBlue(item, processBleData)
}
function onSendData() {
  // sendData(processBleData, currentIndex.value, currInputMode.value, currentCheckIndex.value)
  emitter.emit('sendData', [currentIndex.value, currInputMode.value, currentCheckIndex.value])
}
//下面是采集数据后的处理，需要根据当前具体组件的内容重写
function processBleData(getValue) {
  let value = getValue[0]
  let unit = getValue[1]
  console.log(focusCheckItem.value)
  //当点击不是复测框时
  if (!focusCheckItem.value[0]) {
    let q = focusItem.value[0]
    let grp = focusItem.value[1]
    if (grp[q].decimal) {
      grp[q].real_value = value.toFixed(3)
      // console.log('real_value', focusItem.value.real_value)
    } else {
      grp[q].real_value2 = value.toFixed(2)
      // console.log('real_value2', focusItem.value.real_value2)
    }
    grp[q].datetime_work = dateShow()[0]
    grp[q].datetimeUTC = dateShow()[1]
    grp[q].operator_id = currentUser.value[0]
    grp[q].deviceId = worktoolStore.deviceId.currDeviceId
    // if (grp[q].decimal) {
    //   if (grp[q].real_value < grp[q].min_value || grp[q].real_value > grp[q].max_value) {
    //     grp[q].no_pass = true
    //   } else {
    //     grp[q].no_pass = false
    //   }
    // } else {
    //   if (grp[q].real_value2 < grp[q].min_value2 || grp[q].real_value2 > grp[q].max_value2) {
    //     grp[q].no_pass = true
    //   } else {
    //     grp[q].no_pass = false
    //   }
    // }
    calcDvDh()
    onConfirm(q, grp)
    //当点击是复测框时
  } else {
    let q = focusCheckItem.value[1]
    let grp = focusCheckItem.value[2]
    if (grp[q].decimal) {
      grp[q].check_value = value.toFixed(3)
    } else {
      grp[q].check_value2 = value.toFixed(2)
    }
    console.log(grp[q].check_value, grp[q].check_value2)
    onCheckConfirm(q, grp)
  }
}
// onShow(async () => {
//   currentUser.value = [userStore.userInfo.uid, userStore.userInfo.name]
//   //获取可放行用户
//   users.value = userStore.userInfo.users
//   //货期worksubData
//   workMainId.value = worksubStore.currentWorkMainId
//   worksubData.value = worksubStore.records[workMainId.value]
//   // console.log(worksubData.value)
//   //获取workMainData
//   const workMainIndex = workMain.records.findIndex((item) => item.id == workMainId.value)
//   workMainData.value = workMain.records[workMainIndex]
//   // deviceId.value = worktoolStore.deviceId

//   groupWorksubData.value = []
//   for (let i = 0; i < worksubData.value?.length; i += 5) {
//     groupWorksubData.value.push(worksubData.value.slice(i, i + 5))
//   }
//   console.log('grpWorksubData', groupWorksubData.value)
//   calcInit()
//   calcDvDh()
//   currentIndex.value = groupWorksubData.value[0][0].id
//   currentCheckIndex.value = groupWorksubData.value[0][0].id

//   if (workMainData.value.direction === 'CW') {
//     p.value = pcw.value
//   } else if (workMainData.value.direction === 'CCW') {
//     p.value = pccw.value
//   }
//   // console.log(workMainData.value.direction)
//   // console.log(p.value)
// })
onMounted(() => {
  //接收WorkHead发出的事件
  // emitter.on('onClickBlue', onClickBlue)
  emitter.on('process', processBleData)
  emitter.on('onSendData', onSendData)
  currentUser.value = [userStore.userInfo.uid, userStore.userInfo.name]
  //获取可放行用户
  users.value = userStore.userInfo.users
  //货期worksubData
  workMainId.value = worksubStore.currentWorkMainId
  worksubData.value = worksubStore.records[workMainId.value]
  // console.log(worksubData.value)
  //获取workMainData
  const workMainIndex = workMain.records.findIndex((item) => item.id == workMainId.value)
  workMainData.value = workMain.records[workMainIndex]
  // deviceId.value = worktoolStore.deviceId

  // await getWorksubData(worksubStore.currentWorkMainId)
  groupWorksubData.value = []
  // console.log(worksubData.value.length)

  for (let i = 0; i < worksubData.value?.length; i += 5) {
    groupWorksubData.value.push(worksubData.value.slice(i, i + 5))
  }
  console.log(groupWorksubData.value)
  calcInit()
  calcDvDh()
  // grpForDvDh.value = new Array(groupWorksubData.value.length)
  currentIndex.value = groupWorksubData.value[0][0].id
  currentCheckIndex.value = groupWorksubData.value[0][0].id

  if (workMainData.value.direction === 'CW') {
    p.value = pcw.value
  } else if (workMainData.value.direction === 'CCW') {
    p.value = pccw.value
  }
  console.log(workMainData.value.direction)
  console.log(p.value)
})
onUnmounted(() => {
  //关闭WorkHead所发出的事件
  // emitter.off('onClickBlue', onClickBlue)
  emitter.off('process', processBleData)
  emitter.off('onSendData')
})
</script>
<style lang="scss" scoped>
.work-page {
  .margin-top-bottom {
    margin: 10px 0;
  }

  .container {
    height: 16.06;
    span,
    checkbox {
      font-size: 12px;
      display: inline-block;
      vertical-align: baseline;
    }
  }
  // .temperature {
  //   display: flex;
  //   flex-direction: row;
  //   justify-content: center;
  //   width: 100%;
  //   .text {
  //     font-size: 12px;
  //     font-weight: 700;
  //     color: blueviolet;
  //     width: 70px;
  //   }
  //   .input {
  //     width: 30px;
  //   }
  // }
  .temperature {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center; // 添加垂直居中
    flex-wrap: wrap; // 允许换行
    width: 100%;
    gap: 10px; // 添加间距
    padding: 10px 0; // 添加上下内边距

    .text {
      font-size: 12px; // 增大字体
      font-weight: 700;
      color: blueviolet;
      white-space: nowrap; // 防止文字换行
    }

    .input {
      width: 50px; // 增加输入框宽度

      input {
        width: 100%;
        height: 36px;
        border: 1px solid #dcdfe6;
        border-radius: 4px;
        padding: 0 8px;
        box-sizing: border-box;
        background-color: #fff;

        &:focus {
          border-color: #1598fa;
          outline: none;
        }
      }
    }
  }
  .table {
    .input {
      width: 70px;
      height: 40px;
      text-align: center;
      // background-color: $uni-text-color-disable;
      background-color: #e0e0e0;
      background-color: $text-font-color-4;
      border-radius: 15%;
      // border: 1px solid #000;
    }

    .check {
      width: 70px;
      height: 40px;
      text-align: center;
      // background-color: $uni-text-color-disable;
      background-color: #e0ffff;
      // background-color: $text-font-color-4;
      border-radius: 15%;
      // border: 1px solid #000;
    }

    .active {
      color: #e64340;
    }

    .text {
      font-size: 12px;
      text-align: center;
      color: $text-font-color-2;
    }

    .grp {
      display: flex;
      flex-direction: row;
      justify-content: center;
      font-weight: 700;
      color: $brand-theme-color;
    }

    .nkey {
      display: flex;
      flex-direction: row;
      justify-content: center;
      font-weight: 700;
      //4号模板不需要复测，所以不设置下面颜色
      // color: $brand-theme-color;
    }
  }
}
</style>
